package com.allen.mapper;

import com.allen.bean.Attention;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: allen
 * @Data: 2021.06.27.14:25
 **/
@Mapper //标记mapper文件位置，否则在Application.class启动类上配置mapper包扫描
@Repository
public interface AttentionMapper {

    /**
     * 查询想要关注的人是否已关注
     * @param username
     * @param a_username
     * @return
     */
    @Select(value="select id from attentions where username=#{username} and a_username=#{a_username}")
    Integer find(String username,String a_username);

    @Select(value="select id from attentions where username=#{username} and a_username=#{a_username}")
    Attention findIdByName(String username,String a_username);

    /**
     * 查询所有关注的人
     * @param username
     * @return
     */
    @Select(value="select * from attentions where username=#{username}")
/*
    @Select(value="select a_username from attentions where username=#{username}")
*/
    List<Attention> findUsernameByUsername(@Param("username") String username);

    /**
     * 添加关注
     * @param attention
     * @return
     */

    @Insert(value="insert into attentions(username,a_username)values(#{username},#{a_username})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Integer addAttention(Attention attention);

    /*@Insert(value="insert into attentions value(#{id},#{username},#{a_username})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Integer addAttention(Attention attention);*/

    /**
     * 取消关注
     * @param attention
     * @return
     */
    @Delete(value = "delete from attentions where username=#{username} && a_username=#{a_username}")
    Integer delectName(Attention attention);
}
